{include file='news/header'}
<div class="container">
    <h1 class="page-header"><a href="./list">TP应用示例</a></h1>
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-warning">
                <div class="panel-heading">
                    <h2 class="text-center">新闻列表</h2>
                </div>
                <div class="panel-body">
                    <div class="list-group" style="margin-bottom: 50px;">
                        <a href="./edit"><button type="button" class="btn btn-success pull-right" data-target="#exampleModal">新增</button></a>
                    </div>
                    <div class="list-group">
                        {if $list}
                            {foreach $list as $news}
                            <div class="" style="margin-bottom: 50px;">
                                <a href="./detail?id={$news['id']}" class="list-group-item">
                                    <h3>{$news['title']}</h3>
                                    <p>{$news['description']}</p>
                                </a>
                                <div class="pull-right">
                                    <a href="javascript:;" type="button" class="btn btn-danger" onclick="deleteData({$news['id']})">删除</a>
                                    <a href="./edit?id={$news['id']}"><button type="button" class="btn btn-info" data-target="#exampleModal">编辑</button></a>
                                </div>
                            </div>
                            {/foreach}
                        {else/}
                            No news found.
                        {/if}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    function deleteData(id){
        var url = "./delete";
        $.post(url, {id: id}, function(data) {
            if (0 == data.code) {
                alert(data.message)
                window.location.reload()
            }
        });
    }
</script>
</html>